package com.shanghai.market.plshnaghai.model.login;

import com.google.gson.Gson;
import com.shanghai.market.plshnaghai.abstracts.AbstractModelPost;
import com.shanghai.market.plshnaghai.constants.UrlConstants;
import com.shanghai.market.plshnaghai.entity.login.MaterialWrite;
import com.shanghai.market.plshnaghai.entity.login.MaterialWriteResponse;
import com.shanghai.market.plshnaghai.interfaces.IObjectView;
import com.shanghai.market.plshnaghai.net.HttpManager;

/**
 * Created by Administrator on 2017/8/17.
 */

public class MaterialWriteModel extends AbstractModelPost {
    private IObjectView<MaterialWrite> view;

    public MaterialWriteModel(IObjectView<MaterialWrite> view) {
        super();
        this.view = view;
    }

    @Override
    public void getData(String... args) {
        HttpManager manager = HttpManager.getInstance();

        manager.post(UrlConstants.SUBMIT_PHONE, getParams(), lisenter(), errorListener());
    }

    @Override
    protected void error(String message) {
        view.failure(message);
    }

    @Override
    protected void success(Object result) {
        Gson gson = new Gson();
        MaterialWriteResponse t = gson.fromJson(result.toString(), MaterialWriteResponse.class);
        String message = t.getErrorMessage();
        final String status = t.getStatus();
        if ("OK".equals(status)) {
            MaterialWrite data = t.getData();
            view.success(data);
        } else {
            view.failure(message);
        }
    }
}
